<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-9-25
 * Time: 下午2:06
 * @author 郑钟良<zzl@ourstu.com>
 */

namespace Usercenter\Model;
use Think\Model;

class LabelModel extends Model {

    protected $tableName='label';

    protected $_auto=array(
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('update_time', NOW_TIME, self::MODEL_BOTH),
        array('status', '1', self::MODEL_INSERT),
    );

    protected $insertFields = 'title'; // 新增数据的时候允许写入
    protected $updateFields = 'title'; // 编辑数据的时候允许写入

    public function add_label($data){
        $data=$this->create($data);
        $res=$this->add($data);
        return $res;
    }

    public function update_label($data){
        $id=$data['id'];
        $data=$this->create($data);
        $res=$this->where(array('id'=>$id))->save($data);
        return $res;
    }

    public function get_label($data){
        if(isset($data['id'])&&$data['id']!==0){
            $label_info=$this->where(array('id'=>$data['id']))->find();
        }else{
            if(isset($data['title'])&&$data['title']!==''){
                $label_info=$this->where(array('title'=>$data['title']))->find();
            }
        }
        return $label_info;
    }

    public function delete_label($data){
        if(isset($data['id'])&&$data['id']!==0){
            $res=$this->where(array('id'=>$data['id']))->delete();
        }else{
            if(isset($data['title'])&&$data['title']!==''){
                $res=$this->where(array('title'=>$data['title']))->delete();
            }
        }
        return $res;
    }
} 